package store.lunangangster.bpmn.converter.parser;

import javax.xml.stream.XMLStreamReader;
import store.lunangangster.bpmn.model.BaseElement;
import store.lunangangster.bpmn.model.BpmnModel;
import store.lunangangster.bpmn.model.UserTask;
import store.lunangangster.bpmn.util.XmlStreamUtil;

public class HumanPerformerParser extends BaseChildElementParser {

  @Override
  public void parseChild(XMLStreamReader xsr, BaseElement parentElement, BpmnModel model) throws Exception {
    UserTask userTask = (UserTask) parentElement;
    String resourceName = XmlStreamUtil.toNext(xsr);
    if (ELEMENT_RESOURCE_ASSIGNMENT.equals(resourceName)) {
      String express = XmlStreamUtil.toNext(xsr);
      if (ELEMENT_FORMAL_EXPRESS.equals(express)) {
        String content = xsr.getElementText();
        userTask.setCandidateUser(content);
      }
    }
  }

  @Override
  public String getTargetName() {
    return ELEMENT_HUMAN_PERFORMER;
  }
}
